On the other hand, the basic key-value coding methods, valueForKey: and takeValue:forKey: (valueForKey and takeValueForKey in Java), are the public interface to an enterprise object. They are invoked by clients external to the object (such as for interactions with user interface or other business object logic).
Enterprise object classes can take advantage of this distinction to perform additional processing in accessor methods except when the object is being initialized with values from an external store. For instance, suppose an object wanted to update a total whenever the bonus was set:
void setBonus(double newBonus) {This code should be activated when the object is updated with values provided by a user through the application's user interface, but not when the bonus property is restored from the database. Since the Framework restores the property using takeStoredValue:forKey: (takeStoredValueForKey in Java) and since this method accesses the _bonus instance variable in preference to calling the accessor, the unnecessary (and possibly harmful) recomputation of _total is avoided. If the object actually wants to intervene when a property is set from the database, it has two options:
willChange();
_total += (newBonus - _bonus);
}
Table of Contents
Next Section